<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class login extends CI_Controller {

	public function __construct() {

		parent::__construct();
	}

	public function index() {

		$this->load->view('view_header');
		$this->load->view('login');
		$this->load->view('view_footer');
	}

	public function checkUser() {

	  	if($_POST) {
	      	$un = $_POST['un'];
	      	$pw = $_POST['pw'];
	        
	        $this->load->model('model_login');

	        switch ($this->model_login->check($un, $pw)) {
	        	case 0:
	        		$phanloai = "No";
	        		break;
	        	case 1:
	        		$phanloai = "Học sinh";
	        		break;
	        	case 2:
	        		$phanloai = "Phụ huynh";
	        		break;
	        	case 3:
	        		$phanloai = "Giáo viên";
	        		break;
	        	default:
	        		$phanloai = "No";
	        		break;
	        }

			if ($phanloai != "No") {
				$this->session->set_userdata('prie_username', $un);
				$this->session->set_userdata('prie_phanloai', $phanloai);
				echo "yes";
			} else {
				echo "no";
			}
  		}
	}

	public function logout() {

		$this->session->set_userdata('prie_username', null);
		$this->session->set_userdata('prie_phanloai', null);
		redirect(base_url());
	}

}